<?php
/**
 * Created by PhpStorm.
 * User: hotpot
 * Date: 2018/4/8
 * Time: 10:07
 */

namespace Common\Model;
use Think\Model;
use Think\Model\RelationModel;

class ZykindModel extends BaseModel
{
// 定义自动验证规则
    protected $_validate=array(
        array('kind_name','require','种类名称必填'),
    );

    // 添加数据
    public function addData(){
        $data=I('post.');
        if($this->create($data)){
            $kind_id=$this->add($data);
            return $kind_id;
        }else{
            return false;
        }
    }

    // 修改数据
    public function editData(){
        $data=I('post.');
        if($this->create($data)){
            $this->where(array('kind_id'=>$data['kind_id']))->save($data);
            return true;
        }else{
            return false;
        }
    }

    // 传递is_delete和is_show获取对应数据
    public function getDataByState($is_delete=0,$is_show=1){
        $where=array(
            'is_delete'=>$is_delete,
            'is_show'=>$is_show,
        );
        // 如果是获取全部链接；则删除is_show限制
        if ($is_show==='all') {
            unset($where['is_show']);
        }
        return $this->where($where)->select();
    }

    // 传递lid获取单条数据
    public function getDataByLid($kind_id){
        return $this->where(array('kind_id'=>$kind_id))->find();
    }
}